import Vue from "vue";
import Vuex from "vuex"

//一定要在创建仓库之前将vuex注册为vue的插件
Vue.use(Vuex)

//创建仓库  仓库中的state配置会转绑给store对象
const store = new Vuex.Store({
    strict: true,
    state:{
        count:"",
    },
    mutations:{
        add(state,{count}){
            if(count !== 1){
                state.count=count;
            }else {
                state.count++
            }
        },
    },
    actions:{
        add(store,{count}={count:1}){
            // store.commit("add",{count})
            store.commit({
                type:"add",
                count
            })
        },
        asyncAdd(store,{count}={count:1}){
            setTimeout(()=>{
                store.commit("add",{count})
            },2000)
        }
    }
})

export default store